Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errctx, types, sessionctx: avoid memory allocation in HandleError and reduce allocation in creation of statement context #49280

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

YangKeao
Copy link
Member

@YangKeao YangKeao commented Dec 8, 2023

What problem does this PR solve?

Issue Number: close #49277

Problem Summary:

We use a function closure to represent the function used to append warning, which actually creates a struct on heap to store the closure. A smaller example can be found in #49277 . Here I try to use an interface to remove this memory allocation.

What changed and how does it work?

Use an interface rather than the closure to reduce the memory allocation.

Before:

BenchmarkErrCtx
BenchmarkErrCtx-16    	32070070	        35.62 ns/op
PASS

After:

BenchmarkErrCtx
BenchmarkErrCtx-16    	165152647	         7.261 ns/op
PASS

It doesn't allocate heap memory anymore, which will be even more helpful when the GC pressure is heavy.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Release note

None

@YangKeao YangKeao added the release-note-none Denotes a PR that doesn't merit a release note. label Dec 8, 2023
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 8, 2023
@YangKeao YangKeao force-pushed the fix-alloc branch 3 times, most recently from da74a72 to 728130f Compare December 8, 2023 06:25
Copy link

codecov bot commented Dec 8, 2023

Codecov Report

Merging #49280 (3780ce7) into master (90e272a) will increase coverage by 0.9008%.
Report is 11 commits behind head on master.
The diff coverage is 62.0689%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49280        +/-   ##
================================================
+ Coverage   71.0490%   71.9498%   +0.9008%     
================================================
  Files          1368       1409        +41     
  Lines        402149     416358     +14209     
================================================
+ Hits         285723     299569     +13846     
- Misses        96553      97939      +1386     
+ Partials      19873      18850      -1023     
Flag Coverage Δ
integration 43.9530% <62.0689%> (?)
unit 71.0490% <ø> (-0.0001%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9663% <ø> (ø)
parser ∅ <ø> (∅)
br 48.0250% <ø> (-4.9065%) ⬇️

pkg/errctx/context.go Outdated Show resolved Hide resolved
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
@YangKeao
Copy link
Member Author

YangKeao commented Dec 8, 2023

/retest

Copy link

ti-chi-bot bot commented Dec 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lcwangchao, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [lcwangchao,tangenta]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 11, 2023
Copy link

ti-chi-bot bot commented Dec 11, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-08 06:26:52.877943583 +0000 UTC m=+1768041.543169778: ☑️ agreed by lcwangchao.
  • 2023-12-11 03:05:47.530649552 +0000 UTC m=+239038.567876479: ☑️ agreed by tangenta.

@ti-chi-bot ti-chi-bot bot merged commit e8d7b39 into pingcap:master Dec 11, 2023
16 checks passed
@YangKeao
Copy link
Member Author

YangKeao commented Dec 11, 2023

The profile of BenchmarkErrCtx

Before:

image

After:

image

It shows that after applying this patch, ErrCtx doesn't allocate from heap now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use interface rather than closure in *ctx to remove memory allocation
3 participants